import { UseSearch, UseTable } from '@/components';
import { Card, Modal,Button,Upload,Input, Tabs,Radio,message } from 'antd';
import React from 'react';
import {getStr} from '../../../components/function';
import moment from 'moment';
import LeanController from '../../../services/LeanProject/LeanController';

const {TextArea} = Input
const {confirm} = Modal
class SelfDepartment extends React.Component {
    constructor(props) {
        super(props);
        const userInfo = JSON.parse(sessionStorage.getItem("userInfo"))
        this.state = {
            userInfo:userInfo,
            freshen:false,
            datas:{}
          };
    }
    getList=(query)=>{
        let {userInfo} = this.state
        if(userInfo.roleName.includes("市级部门负责人")){
            query.cityDepartmentName = userInfo.cityDepartmentName
        }
        else if(userInfo.roleName.includes("省级部门负责人")){
            query.provinceDepartmentName = userInfo.provinceDepartmentName
        }
        else{
            query.provinceDepartmentName =""
        }
        query.reviewStep = "本部门审批"
        return LeanController.getList(query)
    }
    handleSearch=(query)=>{
        this.setState({query})
        this.freshen()
    }
    reset=()=>{
        this.setState({query:{}})
        this.freshen()
    }
    showModal=(rowData)=>{
        this.setState({
            rowData,
            visible:true
        })
    }
    submit=()=>{
        let {datas,userInfo,rowData}=this.state
        
        if(!datas.reviewResult){
            message.error("请选择审批意见")
            return
        }
        let that = this
        datas.targs = userInfo.targs
        datas.reviewStep = '本部门审批'
        datas.projectCode = rowData.projectCode
        
        datas.name = userInfo.name
        datas.userName = userInfo.userName
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                LeanController.reviewSubmit(datas).then(r=>{
                    if(r&&r.data===2){
                        message.success('提交成功')
                        that.setState({visible:false})
                        that.freshen()
                    }
                })
            }
        })
    }
    handleChange=(key,e)=>{
        let {datas} = this.state
        datas[key] =e.target.value
        this.setState({datas})
    }
    freshen=()=>{
        this.setState({freshen:!this.state.freshen})
    }
    render() {
        const {visible,rowData,query,freshen} = this.state

        const columns=[
            {title:'课题名称',dataIndex:'projectName',align:'center'},
            {title:'项目负责人',dataIndex:'projectLeaderName',align:'center'},
            {title:'建议名称',dataIndex:'proposalName',align:'center',render:text=>getStr(text)},
            {title:'存在问题描述',dataIndex:'problemDescription',align:'center',render:text=>getStr(text)},
            {title:'具体措施',dataIndex:'proposal',align:'center',render:text=>getStr(text)},
            {title:'被建议部门',dataIndex:'proposalDepartment',align:'center',render:text=>getStr(text)},
            {title:'申报时间',dataIndex:'createdAt',align:'center',render:text=>moment(text).format("YYYY-MM-DD")},
            {title:'审核步骤',dataIndex:'reviewStep',align:'center'},
            {title:'审核结果',dataIndex:'reviewResult',align:'center'},
            {title:'操作',dataIndex:'id',render:(text,rowData)=>{return<div>
                {rowData.reviewResult==='待审批'&&<Button onClick={this.showModal.bind(this,rowData)} style={{margin:5}} type={'danger'}>审批</Button>}
            </div>}},
        ]
        const searchItem=[
            {name:'项目名称',keyName:'projectName',valueType:'text'},
            {name:'审核步骤',keyName:'reviewStep',valueType:'text'},
            {name:'审核结果',keyName:'reviewResult',valueType:'select',selectDatas:[{code:'待审批',name:'待审批'},{code:'已审批',name:'已审批'}]},
            
        ]
        return (
            <div>
                <Card>
                    <UseSearch searchItem={searchItem} handleSearch={this.handleSearch} reset={this.reset}/>
                </Card>
                <Card>
                    <UseTable getData={this.getList} columns={columns} query={query} refresh={freshen} rowKey={'id'}/>
                </Card>
                {visible&&<Modal
                visible={visible}
                title={'审批'}
                onCancel={()=>this.setState({visible:false})}
                onOk={this.submit}
                >
                    <div>
                        <strong>意见：</strong>
                        <Radio.Group onChange={this.handleChange.bind(this,'reviewResult')}>
                            <Radio value={"同意"} key={1}>同意</Radio>
                            <Radio value={"不同意"} key={2}>不同意</Radio>
                        </Radio.Group>
                    </div>
                    <div>
                        <strong style={{verticalAlign:"top"}}>备注：</strong>
                        <Input.TextArea placeholder="请输入" onChange={this.handleChange.bind(this,'reviewRemark')} style={{width:350}}></Input.TextArea>
                    </div>
                </Modal>}   
            </div>
        );
    }
}

export default SelfDepartment;